package com.hns.can.mainte.web;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.hns.can.mainte.vo.MaintenanceVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hns.can.base.entity.SysUserEntity;
import com.hns.can.common.domain.GridPage;
import com.hns.can.common.web.BaseController;
import com.hns.can.mainte.entity.AppCarMaintenRmndrInfoEntity;
import com.hns.can.mainte.entity.AppPartReplaceSetEntity;
import com.hns.can.mainte.service.FunMaintenaSetService;
import com.hns.can.mainte.vo.AppPartsReplaceSetParamVo;
import com.hns.frame.mybatis.Pagination;
import com.hns.tool.pub.PubUtil;

/**
 * 维保设置
 * @author:yecb
 * @email:lps00@163.com
 * @version Revision 2.0.0
 */
@Controller
@RequestMapping("/funMaintenaSet")
public class FunMaintenaSetController extends BaseController  {
    
    @Autowired
    private FunMaintenaSetService funMaintenaSetService;
   
    /**
     * 更换零配件保存
     * @return
     * @throws Exception
     * @author:yecb
     * @email:lps00@163.com
     */
    @RequestMapping("/savePartsReplaceSetInfo")
    @ResponseBody
    public Object savePartsReplaceSetInfo(AppPartsReplaceSetParamVo appPartsReplaceSetParamVo) throws Exception {
    	SysUserEntity user = getCurrentUser().getUser();
        funMaintenaSetService.savePartsReplaceSetInfo(appPartsReplaceSetParamVo, user);
        return this.getReturnResult();
    }
    /**
     * 零配件查询
     * @return
     * @throws Exception
     * @author:yecb
     * @email:lps00@163.com
     */
    @RequestMapping("/getPartsReplaceSetInfo")
    @ResponseBody
    public Object getPartsReplaceSetInfo( @RequestParam(value = "carType", required = false) String carType,@RequestParam(value = "mntMile", required = false) String mntMile) throws Exception {
    	SysUserEntity user = getCurrentUser().getUser();
    	Map<String, Object> map = new HashMap<String, Object>();
        map.put("carType", carType);
        map.put("mntMile", mntMile);
        map.put("corpId", user.getCorpId());
        List<AppPartReplaceSetEntity>  appCarMaintenInfoList= funMaintenaSetService.getPartsReplaceSetInfo(map);
        return this.getReturnResult(appCarMaintenInfoList.get(0));
    }
    
    /**
     * 零配件查询
     * @return
     * @throws Exception
     * @author:yecb
     * @email:lps00@163.com
     */
    @RequestMapping("/getPartsReplaceSetInfoList")
    @ResponseBody
    public Object getPartsReplaceSetInfoList() throws Exception {
    	  Map<String, Object> map = new HashMap<String, Object>();
          map.put("corpId", getCurrentUser().getUser().getCorpId());
          Pagination page= funMaintenaSetService.getPartsReplaceSetInfoList(map);
          GridPage grid = new GridPage(page);
          return this.getReturnResult(grid);
    }
    
    /**
     * 查询维保计划信息
     * @return 返回维保计划数据
     * @throws Exception
     * @author:yecb
     * @email:lps00@163.com
     */
    @RequestMapping("/getMaintenRmndrSetInfo")
    @ResponseBody
    public Object getMaintenRmndrSetInfo( @RequestParam(value = "rcrdId", required = false) String rcrdId) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("rcrdId", rcrdId);
        AppCarMaintenRmndrInfoEntity rmndrInfo = funMaintenaSetService.getMaintenRmndrSetInfo(map);
        return this.getReturnResult(rmndrInfo);
    }
    /**
     * 查询维保计划信息
     * @return 返回维保计划数据
     * @throws Exception
     * @author:yecb
     * @email:lps00@163.com
     */
    @RequestMapping("/getMaintenRmndrSetInfoList")
    @ResponseBody
    public Object getMaintenRmndrSetInfoList() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("corpId", getCurrentUser().getUser().getCorpId());
        Pagination page= funMaintenaSetService.getMaintenRmndrSetInfoList(map);
        GridPage grid = new GridPage(page);
        return this.getReturnResult(grid);
    }
    /**
     * 更新维保计划
     * @param rmndrInfo
     * @return
     * @throws Exception
     * @author:yecb
     * @email:lps00@163.com
     */
    @RequestMapping("/uptMaintenRmndrSetInfo")
    @ResponseBody
    public Object uptMaintenRmndrSetInfo(AppCarMaintenRmndrInfoEntity rmndrInfo) throws Exception {
    	SysUserEntity user = getCurrentUser().getUser();
        String id = user.getId();
        rmndrInfo.setCorpId(user.getCorpId());
        rmndrInfo.setCrtTime(new Date());
        rmndrInfo.setCrtUser(id);
        rmndrInfo.setUpdateTime(new Date());
        rmndrInfo.setUpdateUser(id);
        
        funMaintenaSetService.uptMaintenRmndrSetInfo(rmndrInfo);
        return this.getReturnResult();
    }
    
    /**
     * 保存或更新维保计划
     * @param rmndrInfo
     * @return
     * @throws Exception
     * @author:yecb
     * @email:lps00@163.com
     */
    @RequestMapping("/saveOrUptMaintenRmndrSetInfo")
    @ResponseBody
    public Object saveOrUptMaintenRmndrSetInfo(AppCarMaintenRmndrInfoEntity rmndrInfo) throws Exception {
        if(PubUtil.isEmpty(rmndrInfo.getRcrdId())){
        	funMaintenaSetService.addMaintenRmndrSetInfo(rmndrInfo,  getCurrentUser().getUser());
        }else{
        	funMaintenaSetService.uptMaintenRmndrSetInfo(rmndrInfo);
        }
        
        
        return this.getReturnResult();
    }
    /**
     * 删除维保计划设置
     * @param rcrdId
     * @return
     * @throws Exception
     * @author:yecb
     * @email:lps00@163.com
     */
    @RequestMapping("/delMaintenRmndrSetInfo")
    @ResponseBody
    public Object delMaintenRmndrSetInfo( @RequestParam(value = "rcrdId", required = false) String rcrdId) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("rcrdId", rcrdId);
        funMaintenaSetService.delMaintenRmndrSetInfo(map);
        return this.getReturnResult();
    }
    /**
     * 删除零部件计划设置
     * @return
     * @throws Exception
     * @author:yecb
     * @email:lps00@163.com
     */
    @RequestMapping("/delPartsReplaceSetInfo")
    @ResponseBody
    public Object delPartsReplaceSetInfo( @RequestParam(value = "carType", required = false) String carType,@RequestParam(value = "mntMile", required = false) String mntMile) throws Exception {
    	SysUserEntity user = getCurrentUser().getUser();
    	Map<String, Object> map = new HashMap<String, Object>();
        map.put("carType", carType);
        map.put("mntMile", mntMile);
        map.put("corpId", user.getCorpId());
        funMaintenaSetService.delPartsReplaceSetInfo(map);
        return this.getReturnResult();
    }

    /**
     * 获取企业对应维保项目
     * @author zhangy
     * @version Revision 2.0.0
     * @email: zhangy2222z@sina.cn
     * @create 2017-04-19 19:53
     **/
    @RequestMapping("/getMaintenaItemInfo")
    @ResponseBody
    public Object getMaintenaItemInfo(String corpId){
        List list = funMaintenaSetService.getMaintenaItemInfo(corpId);
        return this.getReturnResult(list);
    }

    /**
     * 编辑企业对应维保项目
     * @author zhangy
     * @version Revision 2.0.0
     * @email: zhangy2222z@sina.cn
     * @create 2017-04-19 19:53
     **/
    @RequestMapping("/uptMaintenaSetInfo")
    @ResponseBody
    public Object uptMaintenaSetInfo(MaintenanceVo vo){
        String userId = this.getCurrentUser().getUser().getId();
        funMaintenaSetService.uptMaintenaSetInfo(vo, userId);
        return this.getReturnResult();
    }

    @RequestMapping("/getMaintenancePart")
    @ResponseBody
    public Object getMaintenancePart(){
        List list = funMaintenaSetService.getMaintenancePart();
        return this.getReturnResult(list);
    }

    @RequestMapping("/getMaintenaContentInfo")
    @ResponseBody
    public Object getMaintenaContentInfo(MaintenanceVo vo){
        List list = funMaintenaSetService.getMaintenaContentInfo(vo);
        return this.getReturnResult(list);
    }

    @RequestMapping("/uptMaintenaContent")
    @ResponseBody
    public Object uptMaintenaContent(MaintenanceVo vo){
        String userId = this.getCurrentUser().getUser().getId();
        funMaintenaSetService.uptMaintenaContent(vo, userId);
        return this.getReturnResult();
    }

}
